<template>
  <Varticles :listdata="AsList"></Varticles>
  <Vinformal :listDynamic="MsList"></Vinformal>
</template>
<script>
import { defineComponent, ref } from "vue";
import { likeAndCollection } from "../../api/showUser";
import Varticles from "../userHome/article";
import Vinformal from "../userHome/informal";

export default defineComponent({
  components: {
    Varticles,
    Vinformal,
  },

  setup() {
    let AsList = ref([]);
    let MsList = ref([]);

    likeAndCollection({
      url: "/showUsers/likeAndCollection",
      uid: sessionStorage.getItem("userID"),
      success: (res) => {
        // console.log(res.data);
        AsList.value.length = 0;
        MsList.value.length = 0;
        for (let i = 0; i < res.data.length; i++) {
          if (res.data[i].type == "As") {
            AsList.value.push({
              aid: res.data[i].aid,
              author: res.data[i].author,
              title: res.data[i].title,
              description: res.data[i].description,
              coverImg: res.data[i].coverImg,
              viewNum: res.data[i].viewNum,
              likeNum: res.data[i].likeNum,
              collectionNum: res.data[i].collectionNum,
              commentNum: res.data[i].commentNum,
            });
          } else {
            MsList.value.push({
              did: res.data[i].did,
              imgHead: "http://localhost:3000/" + res.data[i].imgHead,
              author: res.data[i].author,
              showtime: res.data[i].showtime,
              content: res.data[i].content,
              likeNum: res.data[i].likeNum,
              collectionNum: res.data[i].collectionNum,
              picList: res.data[i].picList,
              commentNum: res.data[i].commentNum,
            });
          }
        }
      },
      err: (err) => {
        console.log(err);
      },
    });

    return {
      AsList,
      MsList,
    };
  },
});
</script>